package com.biostime.qdingding.modules.qd.api;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.biostime.qdingding.common.api.FastResponse;
import com.biostime.qdingding.common.api.ListResponse;
import com.biostime.qdingding.common.api.ObjResponse;
import com.biostime.qdingding.common.web.BaseController;
import com.biostime.qdingding.modules.qd.api.dto.AssessComment;
import com.biostime.qdingding.modules.qd.api.dto.BalanceDto;
import com.biostime.qdingding.modules.qd.api.dto.ContractDto;
import com.biostime.qdingding.modules.qd.api.dto.MyCourseParamDto;
import com.biostime.qdingding.modules.qd.api.dto.CourseOrderDto;
import com.biostime.qdingding.modules.qd.api.dto.CoursesOrderingDto;
import com.biostime.qdingding.modules.qd.api.dto.MyCourseDto;
import com.biostime.qdingding.modules.qd.api.dto.CourseCalendarParamDto;
import com.biostime.qdingding.modules.qd.api.dto.CourseMessageDto;
import com.biostime.qdingding.modules.qd.entity.Comment;
import com.biostime.qdingding.modules.qd.entity.Course;
import com.biostime.qdingding.modules.qd.entity.Student;
import com.biostime.qdingding.modules.qd.service.AlbumService;
import com.biostime.qdingding.modules.qd.service.CommentService;
import com.biostime.qdingding.modules.qd.service.ContractService;
import com.biostime.qdingding.modules.qd.service.CourseOrderService;
import com.biostime.qdingding.modules.qd.service.CourseService;
import com.biostime.qdingding.modules.qd.service.MemberService;
import com.biostime.qdingding.modules.qd.service.PriceService;
import com.biostime.qdingding.modules.qd.service.StudentService;
import com.biostime.qdingding.modules.qd.service.TransrecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 我的课程
 * 
 * @author chenweicheng
 * @version 2015-11-06
 */
@RestController
@RequestMapping(value = "${adminPath}/qd/api/myCourse")
public class MyCourseApi extends BaseController {
	
	@Autowired
	private CourseOrderService courseOrderService;

	@Autowired
	private CommentService commentService;

	@Autowired
	private CourseService courseService;

	@Autowired
	private MemberService memberService;

	@Autowired
	private AlbumService albumService;

	@Autowired
	private TransrecordService transrecordService;

	@Autowired
	private PriceService priceService;
	
	@Autowired
	private StudentService studentService;
	
	@Autowired
	private ContractService contractService;

	/**
	 * 我的课程/按类型获取我的课程列表
	 * 已上，未上
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "getMyCourses")
	public ObjResponse<Map<String, Object>> getMyCourses(MyCourseParamDto cd) {
		String message = null;
		Map<String, Object> map = new HashMap<String, Object>();
		List<MyCourseDto> orderList = new ArrayList<MyCourseDto>();
		int errorCode = 0;
		if (cd.getState() == null) {
			message = "参数不能为空";
			errorCode = 1;
		} else {
			
			//分页操作
			PageHelper.startPage(cd.getPageindex(), cd.getPagesize());
			orderList = courseOrderService.apiGetWentOrNot(cd);				
			message = "获取我的课程列表成功";
			errorCode = 0;
		}
		if(!orderList.isEmpty()){
			for (MyCourseDto cod : orderList) {
				String courseId = cod.getCourseId() + "";
				String type = cod.getType() + "";
				int courseBook = courseOrderService.apiCourseBook(courseId, type);
				int courseQueue = courseOrderService.apiCourseQueue(courseId, type);
				HashMap<String,Object> hashMap = courseOrderService.apiCourseQueuing(courseId, String.valueOf(cd.getStudentId()), type);
				if(hashMap != null){
					BigDecimal num = (BigDecimal) hashMap.get("RANK");
					cod.setCourseQueuing(num); 
				}
				cod.setBookNum(courseBook);
				cod.setQueueNum(courseQueue);
			}			
		}
		List<Map<String, Object>> targetList = new ArrayList<Map<String, Object>>();
		// 将orderList按日期分组
		if (orderList != null)
			for (MyCourseDto cod : orderList) {
				boolean editFlag = false;
				for (Map<String, Object> target : targetList) {
					if (cod.getOnday().equals(target.get("date"))) {
						List<MyCourseDto> l = (List<MyCourseDto>) target.get("list");
						l.add(cod);
						editFlag = true;
					}
				}
				if (!editFlag) {
					Map<String, Object> newMap = new HashMap<String, Object>();
					List<MyCourseDto> newTarget = new ArrayList<MyCourseDto>();
					newTarget.add(cod);
					newMap.put("date", cod.getOnday());
					newMap.put("day", cod.getOndayDay());
					newMap.put("list", newTarget);
					targetList.add(newMap);
				}
			}
		
		Student student=new Student(cd.getStudentId()+"");
		BalanceDto balance = transrecordService.getBalance(student); 
		List<ContractDto> listContract=contractService.apiGetContract(String.valueOf(cd.getStudentId()));
		Date limitDate = null;

		if(listContract != null && !listContract.isEmpty()){
			limitDate = listContract.get(0).getEndDate();
		}
		if (balance != null) {
			double money = balance.getSumPay() - balance.getSumCost() - balance.getSumFreeze();
			map.put("balance", priceService.changeMoney(money)); 
			map.put("limit_time", balance.getLimitDate());
		} else {
			map.put("balance", 0);
			map.put("limit_time", limitDate);
		}
		map.put("list", targetList);
	
		PageInfo<MyCourseDto> page = new PageInfo<MyCourseDto>(orderList);
		
		return FastResponse.create().errCode(errorCode).errMsg(message).pageIndex(page.getPageNum())
				.pageSize(page.getPageSize()).total((int) page.getTotal()).hasNext(page.isHasNextPage())
				.obj(map);
	}

	/**
	 * 我的课程/按周获取我的课程列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "getMyCoursesByWeek")
	public ListResponse<Map<String, Object>> getMyCoursesByWeek(CourseCalendarParamDto cd) {
		String message = null;
		List<Map<String, Object>> targetList = new ArrayList<Map<String, Object>>();
		int errorCode = 0;
		if (cd.getWeekFrom() == null || "".equals(cd.getWeekFrom()) || cd.getWeekNum() == 0
				|| cd.getRecordType() == null) {
			message = "参数不能为空";
			errorCode = 1;
		} else {
			targetList = courseOrderService.getMyCourseListByWeek(cd);
			message = "获取我的课程列表成功";
			errorCode = 0;
		}
		return FastResponse.create().errCode(errorCode).errMsg(message).list(targetList);
	}

	/**
	 * 我的课程/按月获取我的课程列表
	 * @return
	 */
	@RequestMapping(value = "getMyCoursesByMonth")
	public ListResponse<Map<String, Object>> getMyCoursesByMonth(CourseCalendarParamDto cd) {
		String message = null;
		List<Map<String, Object>> targetList = new ArrayList<Map<String, Object>>();
		int errorCode = 0;
		if (cd.getMonthFrom() == null || "".equals(cd.getMonthFrom()) || cd.getMonthNum() == 0
				|| cd.getRecordType() == null) {
			message = "参数不能为空";
			errorCode = 1;
		} else {
			targetList = courseOrderService.getMyCourseListByMonth(cd);
			message = "获取我的课程列表成功";
			errorCode = 0;
		}
		return FastResponse.create().errCode(errorCode).errMsg(message).list(targetList);
	}

	/**
	 * 课程评价/发表评价
	 * @Param assessComment
	 */
	@RequestMapping(value = "commentCourse")
	public ObjResponse<String> commentCourse(AssessComment assessComment, HttpServletRequest request) throws Exception {
		int i = 0;
		String message = null;
		String courseId = assessComment.getCourseId();
		String userId = assessComment.getUserId();
		String type = assessComment.getType();
		Course course = new Course();
		String urls = request.getParameter("urls");
		Map<String, Object> map = new HashMap<String, Object>();
		int errCode = 0;

		// 参数校验
		HashMap<String,Object> checkMap = courseOrderService.apiCheckParameter(courseId, "NOT-NULL", userId, type, "NOT-NULL");
		boolean flag = (boolean) checkMap.get("flag");
		String checkMessage = (String) checkMap.get("errMessage");
		
		if (flag) {		
			
			//判断course存不存在，course为普通课程和户外课程的共同体
			course = courseService.apiGetInOrOut(type, courseId);
			Comment comment = new Comment();
			comment.setCategory(type);
			comment.setObjectId(Integer.parseInt(courseId));
			comment.setReplyId(Integer.parseInt(userId));
						
			//发表课程评论
			if (course != null) {
				comment.setContent(assessComment.getContent());
				comment.setScore(assessComment.getTotalCommentStar());
				comment.setScore1(assessComment.getEnvironmentCommentStar());
				comment.setScore2(assessComment.getTeacherCommentStar());
				comment.setScore3(assessComment.getServiceCommentStar());  
				comment.setFromIp(commentService.getIpAddress(request));
				if (memberService.apiGet(userId) != null) {
					comment.setReplyName(memberService.apiGet(userId).getNickname());
				}
				i = commentService.apiInsert(comment);

				//插入评论图片
				if (i != 0) {
					if (urls != null && !urls.equals("")) {
						map.put("type", course.getType());
						map.put("objectId", comment.getId());
						String picRes = urls.replaceAll(".*\\[", "[").replaceAll("\\].*", "]");
						map.put("picRes", picRes);
						albumService.apiInsertAlbums(map);
					}
					message = "发表评价成功";
					errCode = 0;

				} else {
					message = "发表评价失败";
					errCode = 1;
				}
			} else {
				message = "发表评价失败,该课程不存在";
				errCode = 1;
			}

		} else {
			message = "发表评价失败，"+checkMessage;
			errCode = 1;
		}

		return FastResponse.create().errMsg(message).errCode(errCode).obj("发表评价");
	}

	
	/**
	 * 预约课程/批量预约课程
	 * 该接口只能分批请求，分type=0和type=1的情况
	 * @return
	 */
	public HashMap<String,Object> orderCoursesCommon(HttpServletRequest request) throws Exception {
		String message = "";
		int errCode = 0;
		String courseName = null;
		String userId = request.getParameter("userId");
		String type = request.getParameter("type");
		String studentId = request.getParameter("studentId");
		String courseIds = request.getParameter("courseIds");
		List<CourseMessageDto> successList = new ArrayList<CourseMessageDto>();
		List<CourseMessageDto> errorList = new ArrayList<CourseMessageDto>();
		Map<String, List<CourseMessageDto>> mapReturn = new HashMap<String, List<CourseMessageDto>>();
		CourseMessageDto messageDto = null;
		String couponId = request.getParameter("couponId");

		// 参数校验
		HashMap<String,Object> checkMap = courseOrderService.apiCheckParameter("NOT-NULL", studentId, userId, type, "NOT-NULL");
		boolean flag = (boolean) checkMap.get("flag");
		String checkMessage = (String) checkMap.get("errMessage");

		if (flag) {
			
			//批量调用预约方法
			String ids[] = courseIds.split(",");
			for (int j = 0; j < ids.length; j++) {
				
				//将course信息封装到courseMessageDto
				String id = ids[j];
				Course course = courseService.apiGetInOrOut(type, id); 
				if (course != null) {	
					messageDto = new CourseMessageDto();
					messageDto.setId(Integer.parseInt(course.getId()));
					
					//现阶段先写死户外课程系列名称
					if(type.equals("1")){
						messageDto.setSerial("户外课程");				
					}else{
						messageDto.setSerial(course.getSerial()); 
					}
					
					//将course的值set进messageDto
					messageDto.setOndate(course.getOndate()); 
					messageDto.setSection(course.getSection());
					messageDto.setClassroom(course.getClassroom()); 
					messageDto.setPriceType(course.getPriceType());
					messageDto.setClevel(course.getClevel());
					messageDto.setTheme(course.getTheme());
					messageDto.setType(course.getType());
					messageDto.setTeacher(course.getTeacher()); 
					
					//调用courseOrderService方法获取map
					//map里面包含了返回信息，state,id,message
					HashMap<String, Object> map = courseOrderService.apiOrderCourse(course, "order" , userId,studentId,type,couponId);					
					messageDto.setMessage((String) map.get("message")); 
							
					int i = (int) map.get("id");
					String errMessage = (String) map.get("message");
					String courseId = (String) map.get("courseId");
					String state = (String) map.get("state");
					courseName = (String) map.get("courseName");
					Date date = (Date) map.get("date");
										
					//判断map里面的state状态，并做相应的操作
					if (state.equals("true")) {
						if (i != 0) {
							messageDto.setMessage("您已预约成功"); 
							successList.add(messageDto);
							message += "id：" + courseId + ",  日期：" + date + "   " + ",  名称：" + courseName + ",  预约成功。 ";
							errCode = 0;
						} else {
							errorList.add(messageDto);
							message += "id：" + courseId + ",  日期：" + date + "   " + ",  名称：" + courseName + ",  预约失败。 ";
							errCode = 1;
						}
					}  else {
						errorList.add(messageDto);
						message += "id：" + courseId + ",  日期：" + date + "   " + ",  名称：" + courseName + ",   "
								+ errMessage +"。   ";
						errCode = 1;
					}

				}else{
					messageDto = new CourseMessageDto();
					messageDto.setId(Integer.parseInt(id));
					messageDto.setMessage("该课程不存在");
					errorList.add(messageDto);
				} 
			}
		} else {
			message = "预约失败，"+checkMessage;
			errCode = 1;
		}

		mapReturn.put("successList", successList); 
		mapReturn.put("errorList", errorList);
		
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("message", message);
		map.put("errCode",errCode);
		map.put("mapReturn", mapReturn);

		return map;
	}
	
	/**
	 * 预约课程/批量预约课程
	 * (ios)
	 * @return
	 */	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "orderCourses_v1")
	public ObjResponse<Map<String, List<CourseMessageDto>>> orderCourses_v1(HttpServletRequest request) throws Exception {
		HashMap<String,Object> map = orderCoursesCommon(request);
		String message = (String) map.get("message");
		int errCode = (int) map.get("errCode");
		Map<String, List<CourseMessageDto>> mapReturn = (Map<String, List<CourseMessageDto>>) map.get("mapReturn"); 
		return FastResponse.create().errMsg(message).errCode(errCode).obj(mapReturn);		
	}
	
	/**
	 * 预约课程/批量预约课程
	 * (android)
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "orderCourses")
	public ObjResponse<Map<String, List<CourseMessageDto>>> orderCourses(HttpServletRequest request) throws Exception {
		HashMap<String,Object> map = orderCoursesCommon(request);
		String message = (String) map.get("message");
		int errCode = (int) map.get("errCode");
		Map<String, List<CourseMessageDto>> mapReturn = (Map<String, List<CourseMessageDto>>) map.get("mapReturn"); 
		return FastResponse.create().errMsg(message).errCode(errCode).obj(mapReturn);		
	}

	/**
	 * 选课列表/按排序，按筛选条件
	 * 默认页数为1，条数为10，按时间近远排序，以宝宝年龄段为准
	 */
	@RequestMapping(value = "getCourseByOrder")
	public ListResponse<CoursesOrderingDto> getCourseByOrder(HttpServletRequest request) throws Exception {
		
		//默认页数为1，条数为10，按时间近远排序
		int pageindex = 1;
		int pagesize = 10;
		String orderType = "timeup";
		String message = null;
		int errCode = 0;
	
		if (request.getParameter("pageindex") != null && request.getParameter("pageindex") != null) {
			pageindex = Integer.parseInt(request.getParameter("pageindex"));
			pagesize = Integer.parseInt(request.getParameter("pagesize"));
		}
		if (request.getParameter("orderType") != null && !request.getParameter("orderType").equals("")) {
			orderType = request.getParameter("orderType");
		}

		String userId = request.getParameter("userId");
		String studentId = request.getParameter("studentId");
		String centerId = request.getParameter("centerId");
		String serialId = request.getParameter("serialId");
		String levelId = request.getParameter("levelId");
		String courseday = request.getParameter("courseday");
		//String type = request.getParameter("type");
		List<CoursesOrderingDto> orderDtoList = new ArrayList<CoursesOrderingDto>();
		List<CoursesOrderingDto> orderDtoList2 = new ArrayList<CoursesOrderingDto>();
		List<String> levelIds = null;
		List<String> serialIds = null;
		List<String> coursedays = null;
		
		//参数校验
		HashMap<String,Object> checkMap = courseOrderService.apiCheckParameter("NOT-NULL", studentId, userId, "NOT-NULL", centerId);
		boolean flag = (boolean) checkMap.get("flag");
		String checkMessage = (String) checkMap.get("errMessage");		
		if (flag == true) {

			//通过课程年龄段筛选课程,默认为该宝宝的年龄段
			if (levelId != null && !levelId.equals("")) {
				String[] levelIdsArray = levelId.split(",");
				levelIds = new ArrayList<String>();
				for (int i = 0; i < levelIdsArray.length; i++) {
					levelIds.add(levelIdsArray[i]);
				}
			}else{
				if(!studentId.equals(String.valueOf(BasicApi.defaultStudentId))){
					HashMap<String,Object> levelMap = studentService.apiGetLevel(studentId, centerId);
					if(levelMap != null){
						int Id = (int) levelMap.get("id");
						levelIds = new ArrayList<String>();
						levelIds.add(String.valueOf(Id)); 
					}					
				}
			}

			//通过课程系列筛选课程
			if (serialId != null && !serialId.equals("")) {
				String[] serialIdsArray = serialId.split(",");
				serialIds = new ArrayList<String>();
				for (int i = 0; i < serialIdsArray.length; i++) {
					serialIds.add(serialIdsArray[i]);
				}
			}

			//通过日期筛选课程
			if (courseday != null && !courseday.equals("")) {
				String[] coursedaysArray = courseday.split(",");
				for (int i = 0; i < coursedaysArray.length; i++) {
					switch (coursedaysArray[i]) {
					case "Monday":
						coursedaysArray[i] = "周一";
						break;
					case "Tuesday":
						coursedaysArray[i] = "周二";
						break;
					case "Wednesday":
						coursedaysArray[i] = "周三";
						break;
					case "Thursday":
						coursedaysArray[i] = "周四";
						break;
					case "Friday":
						coursedaysArray[i] = "周五";
						break;
					case "Saturday":
						coursedaysArray[i] = "周六";
						break;
					case "Sunday":
						coursedaysArray[i] = "周日";
						break;
					default:
						coursedaysArray[i] = "周日";		
					}

				}
				coursedays = new ArrayList<String>();
				for (int i = 0; i < coursedaysArray.length; i++) {
					coursedays.add(coursedaysArray[i]);
				}
			}
			
			HashMap<String,Object> map = new HashMap<String,Object>();
			map.put("centerId", centerId);
			map.put("studentId", studentId);
			map.put("userId", userId);
			map.put("orderType", orderType);
			//map.put("type", type);
			map.put("levelIds", levelIds);
			map.put("serialIds", serialIds);
			map.put("coursedays", coursedays);
			
			//分页操作
			PageHelper.startPage(pageindex, pagesize);
			if(orderType.equals("timeup") || orderType.equals("timedown")){ 
				orderDtoList = courseService.apiFindCourseOrderDto(map);				
			}else{
				orderDtoList = courseService.apiFindCourseOrderDto2(map);
			}

			//优惠前价格
			double moneyBefore = 0d;
			double moneyAfter = 0d;
			CoursesOrderingDto orderingDto = null;
			List<CourseOrderDto> orderList2 = null;

			//三层循环遍历
			for (int i = 0; i < orderDtoList.size(); i++) {
				orderingDto = orderDtoList.get(i);
				List<CourseOrderDto> orderList = orderingDto.getCourseOrders();
				orderList2 = new ArrayList<CourseOrderDto>();
				for (int z = 0; z < orderList.size(); z++) {
					
					CourseOrderDto orderDto = orderList.get(z);
					Course course = courseService.apiGetInOrOut(String.valueOf(orderDto.getType()), String.valueOf(orderDto.getId()));
					
					//获取优惠前后价格
					HashMap<String,Object> priceMap = priceService.getPriceMap(course, studentId);
					if(priceMap != null){ 
						moneyBefore = (double) priceMap.get("moneyBefore");
						moneyAfter = (double) priceMap.get("moneyAfter");			
					}
					
					//先写死户外课程的系列，待第二阶段再完善
					if (orderDto.getType() == 1) {
						orderDto.setSerial("户外课程");
					}
					
					//如果状态为取消,则设为空
					if(orderDto.getState() != null && orderDto.getState().equals("canceled")){
						orderDto.setState(null); 
					}
					orderDto.setMoneyBefore(moneyBefore);
					orderDto.setMoneyAfter(moneyAfter);
					
					//设置排位中，前面还有几人
					HashMap<String,Object> hashMap = courseOrderService.apiCourseQueuing(String.valueOf(orderDto.getId()), studentId,
							String.valueOf(orderDto.getType()));
					if(hashMap != null ){
						orderDto.setCourseQueuing((BigDecimal)hashMap.get("RANK"));
					}else{
						orderDto.setCourseQueuing(new BigDecimal(0));
					}				
					
					orderList2.add(orderDto);
				}
				orderingDto.setCourseOrders(orderList2);
				orderDtoList2.add(orderingDto);
			}
			
			//按价格进行排序
			if(orderType.equals("priceup") || orderType.equals("pricedown")){				
				orderDtoList2=courseService.getCourseByPrice(orderDtoList2,orderType);				
			}

			message = "获取选课列表成功";
			errCode = 0;
			
		} else {
			message = "获取选课列表失败,"+checkMessage;
			errCode = 1;
		}
		
		return FastResponse.create().errCode(errCode).subCode(0).errMsg(message).list(orderDtoList2);
		
	}

	/**
	 * 选课列表/按周获取选课列表
	 * @return
	 */
	@RequestMapping("getWeekCources")
	public ListResponse<Map<String, Object>> getWeekCources(CourseCalendarParamDto params) {
		int errCode = 0;
		int subCode = 0;
		String msg = "";
		List<Map<String, Object>> list = null;
		if (params.getWeekFrom() == null || params.getWeekFrom().equals("") || params.getWeekNum() == 0
				|| params.getStudentId() == null || params.getStudentId().equals("")) {
			errCode = 1;
			subCode = 0;
			msg = "参数不能为空";
		} else {
			if(params.getLevelId()==0 && params.getCenterId()!=null && !params.getCenterId().equals("")){				
				if(!params.getStudentId().equals(String.valueOf(BasicApi.defaultStudentId))){ 
					HashMap<String,Object> map=studentService.apiGetLevel(params.getStudentId(), params.getCenterId());
					if(map != null){
						int defaultLevelId=(int)map.get("id");	
						params.setLevelId(defaultLevelId);
					}else{
						params.setLevelId(0);
					}					
				}else{
					params.setLevelId(0);
				}
			}
			
			list = courseService.apiCourseCalendar(params);
			errCode = 0;
			subCode = 0;
			msg = "获取成功";
		}
		return FastResponse.create().errCode(errCode).subCode(subCode).errMsg(msg).list(list);
	}

	/**
	 * 选课列表/按月获取选课列表
	 * @return
	 */
	@RequestMapping("getMonthCources")
	public ListResponse<Map<String, Object>> getMonthCources(CourseCalendarParamDto params) {
		int errCode = 0;
		int subCode = 0;
		String msg = "";
		List<Map<String, Object>> list = null;
		if (params.getMonthFrom() == null || params.getMonthFrom().equals("") || params.getMonthNum() == 0
				|| params.getStudentId() == null || params.getStudentId().equals("")) {
			errCode = 1;
			subCode = 0;
			msg = "参数不能为空";
		} else {
			if(params.getLevelId()==0 && params.getCenterId()!=null && !params.getCenterId().equals("")){				
				if(!params.getStudentId().equals(String.valueOf(BasicApi.defaultStudentId))){ 
					HashMap<String,Object> map=studentService.apiGetLevel(params.getStudentId(), params.getCenterId());
					if(map != null){
						int defaultLevelId=(int)map.get("id");	
						params.setLevelId(defaultLevelId);
					}else{
						params.setLevelId(0);
					}					
				}else{
					params.setLevelId(0);
				}
			}
			params.setWeekFrom(null);
			list = courseService.apiCourseCalendar(params);
			errCode = 0;
			subCode = 0;
			msg = "获取成功";
		}
		return FastResponse.create().errCode(errCode).subCode(subCode).errMsg(msg).list(list);
	}
}
